package com.neu.emp;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import com.neu.emile.tb_emp;

/**
		 * 
		 * @author neustu
		 *    通过jdbc完成对emp表的数据录入，录入信息
		 *    （empno：7777，ename：tom，job：salesman，mgr：7839，hiredate：1980-07-06，sal：1200，comm：1000，deptno：10）；
		 */
public class Demo04 {
	private static String url = "jdbc:mysql://localhost:3306/mjq";
	private static String userName = "root";
	private static String pass = "mysql";
	private static String driver = "com.mysql.jdbc.Driver";
	public static Connection conn; 
	public static PreparedStatement ps;
	static {
		try {
		//  驱动的加载   对应的方法是    Class.forName(driver);
			//  先生成下面的代码   然后快捷生成  try{}
			Class.forName(driver);
			//  生成    Connection 对象
			conn=DriverManager.getConnection(url,userName,pass);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	} 
	/**
	 *    录入
	 */
	public static boolean insert(tb_emp e) throws SQLException {
		boolean flag = false;
		String sql = "insert into tb_emp value(?,?,?,?,?,?,?,?)";
		ps= conn.prepareStatement(sql);
		ps.setInt(1, e.getEmpno());
		ps.setString(2,e.getEname());
		ps.setString(3,e.getJob());
		ps.setInt(4, e.getMgr());
		ps.setString(5, e.getHiredate());
		ps.setDouble(6, e.getSal());
		ps.setDouble(7, e.getComm());
		ps.setInt(8, e.getDeptno());
		int a = ps.executeUpdate();
		if(a>0) {
			flag = true;
		}
		return flag;
	}
	public static void main(String[] args) throws SQLException {
		insert(new tb_emp(7777,"tom","salesman",7839,"1980-07-06",1200,1000,10));
	}
}
